<template>
  <div class="app-container">
    <el-row :gutter="10">
      <fold :span="5" :xs="24" :show.sync='sideshow'>
        <el-card shadow="never">
          <org-tree ref="orgTree" modelType="'dept','community','floor','unit','room'" @nodeClick="handleNodeClick"
                    @firstNodeClick="handleNodeClick"/>
        </el-card>
      </fold>
      <el-col :span="sideshow ? 19 : 24" :xs="24">
        <el-card shadow="never">

        <el-form :model="queryParams" ref="queryForm" v-show="showSearch" label-width="68px" class="form-flex">
        <el-row :gutter="20">
            <el-col :span="6" :xs="24">
                    <el-form-item label="合同编号" prop="pactNo">
                    <el-input
                            v-model="queryParams.pactNo"
                            placeholder="请输入合同编号"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
            </el-col>

            <el-col :span="6" :xs="24">
                    <el-form-item label="乙方" prop="partyDept">
                    <el-input
                            v-model="queryParams.partyDept"
                            placeholder="请输入乙方"
                            clearable
                            size="small"
                            @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
            </el-col>
            <el-col :span="6" :xs="24">
                      <el-form-item label="租户类型" prop="leaseType">
                    <el-select v-model="queryParams.leaseType" placeholder="请选择租户类型" clearable size="small">
                      <el-option
                        v-for="item in dict.custom_type"
                        :key="item.dictValue"
                        :label="item.dictLabel"
                        :value="item.dictValue"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
            <el-col :span="6" :xs="24">
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['payfee:leasePact:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['payfee:leasePact:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['payfee:leasePact:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport" v-hasPermi="['payfee:leasePact:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="leasePactList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
             <el-table-column label="合同编号" align="center" prop="pactNo" />
            <el-table-column label="甲方" align="center" prop="deptName" />
            <el-table-column label="甲方联系人" align="center" prop="firstRelation" />
            <el-table-column label="租户类型" align="center" prop="leaseType" >
            <template slot-scope="scope">
                {{ dict.label.custom_type[scope.row.leaseType] }}
            </template>
           </el-table-column>
            <el-table-column label="联系人" align="center" prop="customName" />
            <el-table-column label="手机号码" align="center" prop="partyPhone" />
            <el-table-column label="联系地址" align="center" prop="partyAdd" />
<!--            <el-table-column label="收费项目ID" align="center" prop="chargeItemId" />-->
            <el-table-column label="费用标准" align="center" prop="costMoney" />
            <el-table-column label="收费周期(月)" align="center" prop="chargePeriod" />
            <el-table-column label="首批收款日期" align="center" prop="forPayeeTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.forPayeeTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['payfee:leasePact:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['payfee:leasePact:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
        </el-card>
      </el-col>
    </el-row>
      <LeasePactForm ref="formRef" @cancel="getList" />
  </div>
</template>

<script>

import { listMixin } from "@/utils/mixins/listMixin";
import { listLeasePact, delLeasePact, exportLeasePact } from "@/api/payfee/leasePact";
import LeasePactForm from "./form.vue"

export default {
  name: "LeasePact",
  components:{ LeasePactForm },
  mixins:[ listMixin ],
  dicts: [   'custom_type',  'month_type',   ],
  data() {
    return {
      // 租赁合同表格数据
      leasePactList: [],
      currentNode:{},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pactNo: null,
        deptId: null,
        firstRelation: null,
        firstPhone: null,
        partyDept: null,
        leaseType: null,
        legalPerson: null,
        fixedPhone: null,
        partyPerson: null,
        partyPhone: null,
        partyAdd: null,
        nodeId: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询租赁合同列表 */
    getList() {
      this.loading = true;
      listLeasePact(this.queryParams).then(response => {
        this.leasePactList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleNodeClick(node) {
      this.currentNode = node;
      this.queryParams.nodeId = node.id
      this.getList()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.formRef.show({"type": "ADD","currentNode":this.currentNode});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      const option = {
          "type":"UPDATE",
          "id": id,
        "currentNode":this.currentNode
      }
      this.$refs.formRef.show(option);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除租赁合同编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLeasePact(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有租赁合同数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportLeasePact(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
